package org.ovirt.microvirt.services.events.impl;

import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.ObjectMessage;
import javax.jms.Session;

import org.ovirt.microvirt.beans.events.Event;
import org.ovirt.microvirt.services.events.EventProcessor;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.jms.core.MessageCreator;

public class EventProcessorLaterImpl implements EventProcessor {

	public EventProcessorLaterImpl(final JmsTemplate template) {
		super();
		this.template = template;
	}

	final JmsTemplate template;

	@Override
	public void process(final Event event) {
		template.send(new MessageCreator() {

			@Override
			public Message createMessage(final Session session)
					throws JMSException {
				final ObjectMessage msg = session.createObjectMessage();
				msg.setObject(event);
				return msg;
			}
		});
	}

}
